extensions.org.icongarden.http.writeASCII ("Content-type: text/html\r\n\r\n");
var writeUTF8 = extensions.org.icongarden.http.writeUTF8;

function logState (openFile)
{
	for (var p in openFile)
	{
		writeUTF8 ('<p>' + p + ' is ' + openFile [p] + '</p>');
	}
}

try
{
	var fs = extensions.org.icongarden.fileSystem;
	writeUTF8 ('<p>constructing paths</p>');
	var filePath = ["victim","test"];

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>opening file</p>');
	var openFile = fs.openFile (filePath, {create:true, write:true});

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>removing file</p>');
	fs.remove (filePath); // on UNIX, this works; on Windows, it doesn't

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>logging state of opened file</p>');
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>writing foo</p>');
	writeUTF8 (openFile.write ("foo"));
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>setting byteCount and byteOffset</p>');
	var bc = openFile.byteCount;
	openFile.byteCount = 2000;
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>reading foo</p>');
	openFile.byteOffset = 0;
	writeUTF8 ('<p>' + openFile.read (3) + '</p>');
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>writing bar</p>');
	writeUTF8 (openFile.write ("bar"));
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>reading bar</p>');
	openFile.byteOffset = 3;
	writeUTF8 ('<p>' + openFile.read (3) + '</p>');
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>reading foobar</p>');
	openFile.byteOffset = 0;
	writeUTF8 ('<p>' + openFile.read (6) + '</p>');
	logState (openFile);

	writeUTF8 ('<hr>');
	writeUTF8 ('<p>closing file</p>');
	openFile.close ( );
	logState (openFile);
}
catch (e)
{
	writeUTF8 (e);
}
